﻿Imports System.Text
Imports System.Data.Odbc
Imports MySql.Data.MySqlClient

Public Class DBConnString
    Public Shared Function generarCadenaConexion(ByVal strServer As String, ByVal strPort As String, ByVal strDbName As String, ByVal strUser As String, ByVal strPwd As String) As String
        'Dim connStrBuld As OdbcConnectionStringBuilder = New OdbcConnectionStringBuilder()
        Dim connStrBuld As MySqlConnectionStringBuilder = New MySqlConnectionStringBuilder()
        Try
            'MYSQL
            With connStrBuld
                .Server = strServer
                .Port = Convert.ToInt32(strPort)
                .Database = strDbName
                .UserID = strUser
                .Password = strPwd
            End With
            
            'POSTGRESS
            'connStrBuld.Driver = "PostgreSQL ANSI"
            'connStrBuld("Server") = strServer
            'connStrBuld("port") = strPort
            'connStrBuld("database") = strDbName
            'connStrBuld("uid") = strUser
            'connStrBuld("pwd") = strPwd
            Return connStrBuld.ConnectionString
        Catch ex As Exception
            Throw
        Finally
            connStrBuld = Nothing
        End Try
    End Function

    Public Shared Function generarCadenaConexionParaCrearBD(ByVal strServer As String, ByVal strPort As String, ByVal strUser As String, ByVal strPwd As String) As String
        Dim connStrBuld As MySqlConnectionStringBuilder = New MySqlConnectionStringBuilder()
        Try
            'MYSQL
            With connStrBuld
                .Server = strServer
                .Port = Convert.ToInt32(strPort)
                .UserID = strUser
                .Password = strPwd
            End With
            Return connStrBuld.ConnectionString
        Catch ex As Exception
            Throw
        Finally
            connStrBuld = Nothing
        End Try
    End Function

End Class
